import router from '@/router'
import nprogress from 'nprogress'
import 'nprogress/nprogress.css'
import store from '@/store'


const whiteList = []

router.beforeEach((to, from, next) => {
  nprogress.start()

  if (store.getters.token) {
    if (to.path === '/login') {
      next('/') // 中转到首页 
      nprogress.done()
    } else {
      next()
    }
  } else {
    // token 为空
    if (whiteList.includes(to.path)) {
      next()
    } else {
      next()
    }
  }
})

router.afterEach((to, from, next) => {
  console.log('路由后置守卫');
  nprogress.done()
})

